<template>
  <div class="main">
    <!-- 头部导航栏区域 -->
    <van-nav-bar
      right-text="注册"
      left-arrow
      title="盛红房产"
      @click-left="$router.back()"
      @click-right="$router.push('/register')"
    />
    <!-- 头部导航栏区域 -->
    <h3>寓意枝盛叶茂，红遍大江南北</h3>
    <!-- 图片logo区域 -->
    <div class="logo-img">
    <img src="../../assets/logo2.png" />
    </div>
    <!-- 图片logo区域 -->
    <!-- 标题 -->
    <h3>嗨,欢迎回来！</h3>
    <!-- 标题 -->
    <van-form @submit="onSubmit">
      <van-icon name="manager-o" class="icon icon-user" />
      <van-icon name="goods-collect-o" class="icon icon-password" />
      <van-field v-model="user.identifier" name="账号" placeholder="账号或邮箱">
      </van-field>
      <van-field
        v-model="user.password"
        type="password"
        name="密码"
        placeholder="密码"
        class="van-field-password"
      ></van-field>
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit" color="#4ec7fe"
          >登录</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  name: 'LoginIndex',
  data () {
    return {
      user: {
        identifier: '',
        password: ''
      }
    }
  },

  mounted () {
    const loginForm = document.querySelector('form')
    const loginInput = loginForm.querySelectorAll('input')[0]
    loginInput.autocomplete = 'off'
    loginInput.focus()
  },

  methods: {
    ...mapActions('user', ['userLogin']),
    // 表单提交事件处理函数
    async onSubmit () {
      try {
        await this.userLogin(this.user)
      } catch (error) {
        console.log(68, error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
$textColor: #4ec7fe;
.main {
  ::v-deep .van-nav-bar {
    .van-icon,
    .van-nav-bar__text {
      color: #4ec7fe;
    }
    .van-nav-bar__title{
      color: #4ec7fe;
      font-size: 21px;
    }
  }
    .logo-img{
    margin-top: 30px;
        display: flex;
    justify-content: center;
  }
  img {
    width: 80%;
  }
  h3 {
    text-align: center;
    font-weight: normal;
    margin: 25px 0;
    color: $textColor;
  }
  ::v-deep .van-form {
    position: relative;
    .van-field__control {
      padding-left: 28px;
    }
    .van-field {
      width: 70vw;
      margin: 0 auto;
      background-color: #f7f8fa;
      border-radius: 25px;
    }
    .van-field-password {
      margin-top: 25px;
    }
    .van-button {
      margin: 0 auto;
      margin-top: 35px;
      width: 70vw;
    }
    .icon {
      z-index: 9999;
      position: absolute;
      left: 19%;
      font-size: 25px;
      color: $textColor;
    }
    .icon-user {
      top: 5%;
    }
    .icon-password {
      top: 41%;
    }
  }
}
</style>
